import time
import os
from datetime import datetime

def watch_file(filename, check_interval=0.5):
    last_mtime = None
    print('Log record runing...')
    while True:
        try:
            mtime = os.path.getmtime(filename)
            if mtime != last_mtime:
                with open(filename, 'r', encoding='utf-8') as f:
                    now = datetime.now()
                    time_string = now.strftime("%H:%M:%S")
                    lines = f.read().split('\\n')
                    if len(lines) == 0 or not lines[0]:
                        continue
                    print("[LOG]" + time_string)
                    for line in lines:
                        print(line)
                last_mtime = mtime
        except FileNotFoundError:
            pass
        time.sleep(check_interval)

watch_file('D:\\output.txt')
